package com.yanqu.road.server.cmd.player;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.verification.VerificationProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.verification.VerificationModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_VERIFICATION_UPLOAD_PARAM, desc = "上报验证信息")
public class VerificationUploadParamCmd extends AbstractCommand {

    private int systemId;

    private int type;

    private String param = "";

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VerificationProto.VerificationUploadParamReqMsg reqMsg = VerificationProto.VerificationUploadParamReqMsg.parseFrom(packet.getBytes());
        systemId = reqMsg.getSystemId();
        type = reqMsg.getType();
        param = reqMsg.getParam();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(VerificationModule.class).uploadParam(systemId, type, param);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            VerificationProto.VerificationUploadParamRespMsg.Builder respMsg = VerificationProto.VerificationUploadParamRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_VERIFICATION_UPLOAD_PARAM, respMsg);
        }
    }
}
